﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace QUT.Bio.SilverMap {
	/// <summary>
	/// Interaction logic for HorizontalLayout.xaml
	/// </summary>
	public partial class HorizontalLayout : UserControl, IPageLayout {
		private bool initialised;
		
		public HorizontalLayout () {
			InitializeComponent();
			initialised = true;
		}

		public View View {
			get {
				return view;
			}
		}

		public HitStack Alignment {
			get {
				return alignment;
			}
		}
		
		public SequenceSummaryTable SequenceSummaryTable {
			get {
				return sequenceSummaryTable;
			}
		}
		
		public Grid GeneDetailsPanel {
			get {
				return geneDetailsPanel;
			}
		}

		public SequencePropertyPanel SequencePropertyPanel {
			get {
				return sequencePropertyPanel;
			}
		}

		/// <summary>
		/// Brings the specified user interface element into view.
		/// </summary>
		/// <param name="viewElement"></param>

		public void Show ( FrameworkElement viewElement ) {
			if ( viewElement == geneDetailsPanel ) {
				infoContainer.SelectedItem = geneDetailsContainer;
				geneDetailsContainer.Visibility = Visibility.Visible;
			}
			else if ( viewElement == sequencePropertyPanel ) {
				infoContainer.SelectedItem = sequencePropertyContainer;
			}
			else if ( viewElement == sequenceSummaryTable ) {
				infoContainer.SelectedItem = sequenceSummaryContainer;
			}

			// Everything else is already in view. Do nothing. 
		}

		/// <summary>
		/// Hides the specified user interface element into view.
		/// </summary>
		/// <param name="viewElement"></param>

		public void Hide ( FrameworkElement viewElement ) {
			if ( viewElement == geneDetailsPanel ) {
				if ( infoContainer.SelectedItem == geneDetailsContainer ) {
					infoContainer.SelectedItem = sequencePropertyContainer;
				}
				
				geneDetailsContainer.Visibility = Visibility.Collapsed;
			}

			// Everything else is fixed. Do nothing.
		}
		
		/// <summary>
		/// Get a reference to the history control.
		/// </summary>

		public HistoryPanel HistoryPanel {
			get {
				return historyPanel;
			}
		}

		/// <summary>
		/// Gets a reference to the search control.
		/// </summary>
		
		public SearchControl SearchControl {
			get {
				return searchControl;
			}
		}

		private void infoContainer_SelectionChanged ( object sender, SelectionChangedEventArgs e ) {
			if ( ! initialised ) {
				return;
			}
			
			TextBlock [] tabLabels = {
				sequenceSummaryLiteral, sequencePropertyLiteral, geneDetailsLiteral
			};
			
			foreach ( TextBlock tb in tabLabels ) {
				tb.Visibility = Visibility.Collapsed;
			}

			if ( infoContainer.SelectedItem == sequenceSummaryContainer ) {
				sequenceSummaryLiteral.Visibility = Visibility.Visible;
			}

			if ( infoContainer.SelectedItem == sequencePropertyContainer ) {
				sequencePropertyLiteral.Visibility = Visibility.Visible;
			}

			if ( infoContainer.SelectedItem == geneDetailsContainer ) {
				geneDetailsLiteral.Visibility = Visibility.Visible;
			}
		}
		
	}
}
